/**
 * 功能描述 餐饮落实
 */

define(function (require, exports, module) {
	var Dialog = require("dialog");
	var EditGrid = require("editgrid");
    var instance = {
        initComponent: function (widget) {
        	var cargrid = new EditGrid({
        		parentNode:"#checkInCar",
        		
        		model:{
        			onAdd:function(editors){
        				var carDate = editors["carDate"];
        				var address = editors["address"];
        				var haveCar = editors["haveCar"];
        				var description = editors["description"];
        				
        				if(carDate.getValue() == "" || address.getValue() == "" || haveCar.getValue() == "" ){
							return false;
						}else{
	        				cargrid.add({
	        					carDate : carDate.getValue(),
	        					address : address.getValue(),
	        					haveCar : haveCar.getValue(),
	        					description : description.getValue()
	        				})
	        				var option=[];
						}
        			},
        			columns:[{
        				name:"carDate",
        				label:"用车时间",
        				format:"date",
						/*formatparams:{
							mode:"HH:mm"
						},*/
						editor:{
							type:"date",
							mode: "YYYY-MM-DD",
							onEdit:function(editor,rowIndex,rowData){
								editor.setValue(rowData.carDate);
							},
							onChange:function(plugin,index,rowData){
								
								rowData.carDate = plugin.getValue();
								cargrid.update(index,rowData);
								
							}
						}
        			},{
        				name:"address",
        				label:"派车地址",
        				editor:{
							type:"text",
							placeholder: "请输入派车地址",
							onEdit:function(editor,rowIndex,rowData){
								editor.setValue(rowData.address);
							},
							onChange:function(plugin,index,rowData){
								rowData.address = plugin.getValue();
								cargrid.update(index,rowData);
							}
						}
        			},{
        				name:"description",
        				label:"备注",
        				editor:{
							type:"text",
							placeholder: "请输入备注",
							onEdit:function(editor,rowIndex,rowData){
								editor.setValue(rowData.description);
							},
							onChange:function(plugin,index,rowData){
								rowData.description = plugin.getValue();
								cargrid.update(index,rowData);
							}
						}
        			},{
        				name:"haveCar",
        				label:"是否派车",
        				format : function(value, row) {
        					if(value == true || value
        							== "true" || value.key== true ||value.key== "true" ){
        						return "是"
        					}else{
        						return "否"
        					}
            			},
        				editor:{
        					type:"select",
							placeholder: "请选择是否派车",
							options:[{
								key:true,
								value:"是"
							},{
								key:false,
								value:"否"
							}],
							onEdit:function(editor,rowIndex,rowData){
								editor.setValue(rowData.haveCar.key);
							},
							onChange:function(plugin,index,rowData){
								rowData.haveCar = {
										key:plugin.getValue(),
										value:plugin.getText()
								};
								cargrid.update(index,rowData);
							}
						},
        			},{
						name : "show",
						label : "操作",
						format : "button",
						formatparams : [{
							id : "delete",
//							icon : "icon-remove",
							text:"删除",
							handler : function(index, data, rowEle) {
								widget.get("cargrid").remove(index);
							}
						} ]
					}]
        		}
        	});
        	widget.set("cargrid",cargrid);
        }
    };
    module.exports = instance;
});
